﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebService.Connect;
using System.Data.SqlClient;
using Model;
using System.Data;

namespace WebService.Datalayer
{
    public class DBBooking
    {
        Database db = new Database();
        SqlParameter[] listParameter;

        /// <summary>
        /// SelectBookingsAll
        /// </summary>
        /// <returns></returns>
        public DataSet SelectBookingsAll()
        {
            return db.GetDataset("sp_SelectBookingsAll");
        }

        /// <summary>
        /// SelectMaxBookingNumberInDate
        /// </summary>
        /// <returns></returns>
        public string SelectMaxBookingNumberInDate()
        {
            return db.GetDataset("sp_SelectMaxBookingNumberInDate").Tables[0].Rows[0][0].ToString();
        }

        /// <summary>
        /// SelectMaxBookingId
        /// </summary>
        /// <returns></returns>
        public string SelectMaxBookingId()
        {
            return db.GetDataset("sp_SelectMaxBookingId").Tables[0].Rows[0][0].ToString();
        }

        /// <summary>
        /// SelectBooking
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectBookingsByAndBookingID(Bookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@BookingID", obj.BookingID),
            };
            return db.GetDataSetWithParameter("sp_SelectBookingsByAndBookingID", listParameter);
        }

        /// <summary>
        /// DeleteBooking
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int DeleteBooking(Bookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@BookingID", obj.BookingID),
            };
            return db.ExcuteQueryWithParamater("sp_DeleteBooking", listParameter);
        }
        /// <summary>
        /// SelectBookingByStaffID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectBookingByStaffID(int StaffID)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@StaffID", StaffID),
            };
            return db.GetDataSetWithParameter("sp_SelectBookingsByAndStaffID", listParameter);
        }
        /// <summary>
        /// SelectBookingByTableID
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public DataSet SelectBookingByTableID(int TableID)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@TableID", TableID),
            };
            return db.GetDataSetWithParameter("sp_SelectBookingsByAndTableID",listParameter);
        }
        /// <summary>
        /// InsertBooking
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int InsertBooking(Bookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@BookingID",obj.BookingID),
                new SqlParameter("@TableID",obj.TableID),
                new SqlParameter("@StaffID",obj.StaffID),
                new SqlParameter("@BookingNumber",obj.BookingNumber),
                new SqlParameter("@BookingDate",obj.BookingDate),
                new SqlParameter("@TotalAmount",obj.TotalAmount),
                new SqlParameter("@IsDeleted",obj.IsDeleted),
            };
            return db.ExcuteQueryWithParamater("sp_InsertBooking", listParameter);
        }

       /// <summary>
       ///  UpdateBooking
       /// </summary>
       /// <param name="obj"></param>
       /// <returns></returns>
        public int  UpdateBooking(Bookings obj)
        {
            listParameter = new SqlParameter[]
            {
                new SqlParameter("@TableID",obj.TableID),
                new SqlParameter("@StaffID",obj.StaffID),
                new SqlParameter("@BookingNumber",obj.BookingNumber),
                new SqlParameter("@BookingDate",obj.BookingDate),
                new SqlParameter("@TotalAmount",obj.TotalAmount),
                new SqlParameter("@IsDeleted",obj.IsDeleted),
                new SqlParameter("@BookingID",obj.BookingID),
            };
            return db.ExcuteQueryWithParamater("sp_UpdateBooking",listParameter);
        }
    }
}